<?php
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
form_pr('getResults','','','post');
MYDCONN();
$GLOBALS['MYT'] = $GLOBALS['MYD'];
	if(!isset($_POST['RsDate'])) { $_POST['RsDate'] = date("Y-m-01"); }
	if(!isset($_POST['RsProfit'])) { $_POST['RsProfit'] = 1; }
	$GET = $GLOBALS['MYD']->db_array("SELECT * FROM systemoffice.main_offices
			INNER JOIN officeschema.origenes ON OriNumero = office_number
			INNER JOIN officeschema.dominios ON dom_ID = OriDominio
			LEFT OUTER JOIN finantial_results ON RsOri = office_number AND (RsOffice IS NULL OR RsOffice = ref) AND
			MONTH(RsDate) = MONTH('".$_POST['RsDate']."') AND YEAR(RsDate) = YEAR('".$_POST['RsDate']."') AND RsType = 1 AND RsProfit = {$_POST['RsProfit']}
			WHERE dom_Activo = 1 AND OriTipo IN (2,1) AND OriNumero > 800
				AND OriFechaAlta < '".$_POST['RsDate']."'
				AND (OriFechaBaja > '".$_POST['RsDate']."' OR OriFechaBaja IS NULL)
			ORDER BY OriNumero");
	$TOTAL = 0;
 ?>
<div class="title"> Metas Atribuidas por Loja no periodo
	<?php
	mn_field('date','ED','RsDate',$_POST['RsDate'],'getResults','8','','');
	mn_field('button','ED','Consult','Consultar','','','','" style="padding:4px;margin:2px" onclick="
				document.getResults.action=\'Modules/FTK9D4D0/msetresult.php\';
				subform(\'getResults\',\'app\');');

	$FieldCountries = "SELECT cvt_ID AS ID, cvt_Name AS NAME FROM officeschema.hd_cashiertypes WHERE cvt_Type = 1";
	mn_field('select','ED','RsProfit',$_POST['RsProfit'],$FieldCountries,'Todos','','" style="margin:3px');
	

	mn_field('button','ED','Consult','Validar','','','','" style="padding:4px;margin:2px" onclick="
				document.getResults.action=\'_response/rsproxy.php?pr=cdc_valvalues\';
				subform(\'getResults\',\'RsResponse\');'); ?>
	<div id="RsResponse"></div>
</div>
<table width="100%">
<tr style="cell-padding:5px;background-color:#F2F2F2"><td>Numero</td><td>Loja</td><td>Meta Mensal</td></tr>
<?php
 for($i=1;$i<=$GET[0];$i++) {
	$TOTAL += $GET[$i]['RsAmount'];
 	if($GET[$i]['RsAmount'] == ''){$GET[$i]['RsAmount']=0;}
 echo '<tr height="22px" bgcolor="'.gridlines($i).'"><td>';
	mn_field('hidden','ED','RsID'.$i,$GET[$i]['RsID'],'','','','');
	mn_field('hidden','ED','RsOffice'.$i,$GET[$i]['ref'],'','','','');
	mn_field('text','ED','OriNumero'.$i,$GET[$i]['OriNumero'],5,5,'','" readonly="'); echo '</td>
	<td>'.$GET[$i]['OriNombre'].'</td>
	<td>';
	mn_field('text','ED','RsAmount'.$i,$GET[$i]['RsAmount'],8,8,'','" style="text-align:right'); echo ' EUR</td>
    </tr>';
 } 
 echo '<tr height="22px" bgcolor="'.gridlines($i).'"><td></td>
	<td>Total: </td>
	<td>'.number_format($TOTAL,2,'.',',').' EUR</td>
    </tr>';
	mn_field('hidden','ED','RsCount',$GET[0],'','','','');
	mn_field('hidden','ED','RsType',1,'','','','');
	mn_field('hidden','ED','RsSetProfit',$_POST['RsProfit'],'','','',''); ?>
</table>
</form>